package com.imwenwen.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.imwenwen.pojo.*;
import com.imwenwen.service.*;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Imwenwen
 * @since 2020-12-19
 */
@Controller
public class IndexController {

    @Autowired
    private LakercolumService lakercolumService;
    @Autowired
    private SportscolumService sportscolumService;
    @Autowired
    private BasketballcolumService basketballcolumService;
    @Autowired
    private FootballcolumService footballcolumService;
    @Autowired
    private FocuscolumService focuscolumService;
    @Autowired
    private FocusnewscolumService focusnewscolumService;
    @Autowired
    private FocusheadService focusheadService;
    @RequestMapping({"/","/index"})
    private String index(Model model){

        //湖人栏目
        QueryWrapper<Lakercolum> wrapper01 = new QueryWrapper<>();
        wrapper01.orderByAsc("id").last("limit 24");
        model.addAttribute("lakeritems",lakercolumService.list(wrapper01));

        //体育栏目
        QueryWrapper<Sportscolum> wrapper02 = new QueryWrapper<>();
        wrapper02.orderByAsc("id").last("limit 8");
        model.addAttribute("sportitems",sportscolumService.list(wrapper02));

        //NBA篮球栏目
        QueryWrapper<Basketballcolum> wrapper03 = new QueryWrapper<>();
        wrapper03.orderByAsc("id").last("limit 5");
        model.addAttribute("bbitems",basketballcolumService.list(wrapper03));

        //国际足球栏目
        QueryWrapper<Footballcolum> wrapper04 = new QueryWrapper<>();
        wrapper04.orderByAsc("id").last("limit 5");
        model.addAttribute("fbitems",footballcolumService.list(wrapper04));

        //要闻栏目
        QueryWrapper<Focusnewscolum> wrapper05 = new QueryWrapper<>();
        wrapper05.orderByAsc("id").last("limit 8");
        model.addAttribute("fnitems",focusnewscolumService.list(wrapper05));

        //焦点栏目导航栏头部标题
        //第一个标题获取
        QueryWrapper<Focushead> wrapper06 = new QueryWrapper<>();
        wrapper06.orderByDesc("id").last("limit 1,1");
        //第二个标题获取
        QueryWrapper<Focushead> wrapper07 = new QueryWrapper<>();
        wrapper07.orderByDesc("id").last("limit 0,1");
        model.addAttribute("focusheadfirst",focusheadService.list(wrapper06));
        model.addAttribute("focusheadsecond",focusheadService.list(wrapper07));
//        System.out.println();
//        System.out.println("----test01------->"+focusheadService.list(wrapper06));
//        System.out.println("-----test02------>"+focusheadService.list(wrapper07));
        //焦点新闻
        //第一部分
        QueryWrapper<Focuscolum> wrapper08 = new QueryWrapper<>();
        wrapper08.orderByDesc("id").last("limit 1,1");
        //第二部分
        QueryWrapper<Focuscolum> wrapper09 = new QueryWrapper<>();
        wrapper09.orderByDesc("id").last("limit 0,1");
        model.addAttribute("focusnewsfirst",focuscolumService.list(wrapper08));
        model.addAttribute("focusnewssecond",focuscolumService.list(wrapper09));

        return "front/index";
    }



}

